package com.randi.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.List;

/**
 * Json 序列化器
 *
 * @author ziye
 */
public class LongsToStringSerializer extends JsonSerializer<List<Long>> {

    @Override
    public void serialize(List<Long> longs, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

        String[] stringList = longs.stream().map(Object::toString).toArray(String[]::new);

        jsonGenerator.writeArray(stringList, 0, stringList.length);
    }


}
